<%@page import="models.User"%>
<%@page import="dao.PrivateMessageDao"%>
<%@page import="classes.HibernateUtil"%>
<%@include file="configuration.jsp" %>
<%@page import="classes.Url"%>
<%@page import="java.util.Enumeration"%>
<%@page import="java.util.Arrays"%>
<%@page import="java.util.List"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<header>    
    <div class="logo">
        <a href="${url}"><img src="${url}images/logo.png" border="0" /></a>
    </div>
    <div class="login">
        <c:choose>
            <c:when test="${sessionScope.userdetails!=null}">
                <div class="information">
                    <div class="left">
                        <span>
                            <a href="${url}userProfile?id=${sessionScope.user.member_id}"><img src="${url}images/profile.png" />${sessionScope.userdetails.firstname} ${sessionScope.userdetails.insertion} ${sessionScope.userdetails.lastname}</a>
                        </span>
                        <span>
                            <%
                            // hu(pm), cd(pm), se(pm), pm = private messages
                            HibernateUtil hupm = new HibernateUtil();
                            PrivateMessageDao cdpm = new PrivateMessageDao(hupm.openSession());
                            HttpSession sepm = request.getSession();
                            User uspm = (User) sepm.getAttribute("user");
                            %>    
                            <a href="${url}PrivateMessage"><img src="${url}images/mail.png" />(<strong><%=cdpm.getUnreadMessages(uspm.getMember_id())%></strong>) ${uq_unread_messages}</a>
                        </span>
                    </div>
                    <div class="right">
                        <span>
                            <a href="${url}LoginController">
                                <img src="${url}images/logout.png" /><br />
                                ${uq_logout}
                            </a>
                        </span>
                    </div>
                    <div class="bottom">
                        <span>
                            <c:if test="${sessionScope.user != null && (sessionScope.userrole == 'Administrator' || sessionScope.userrole == 'Teacher')}">
                                <c:if test="${sessionScope.userdetails.role.name == 'Administrator'}">
                                    <span>
                                        <form action="${url}LoginController" method="post" id="enableadminform">
                                            <input type="hidden" value="${url}<%=Url.getUrl(request)%>" name="redir"/>
                                            <input type="hidden" value="0" name="isenabled" id="isenabled" />
                                            <input type="checkbox" name="enableadmin" id="enableadmin" <c:if test="${sessionScope.userrole == 'Administrator'}">checked</c:if> />
                                            <label for="enableadmin"><c:choose><c:when test="${sessionScope.userrole == 'Administrator'}">${uq_disable_administrator_functions}</c:when><c:otherwise>${uq_enable_administrator_functions}</c:otherwise></c:choose></label>
                                        </form>
                                    </span>
                                </c:if>
                            </c:if>
                            <c:if test="${sessionScope.user != null && sessionScope.userrole != 'Administrator' && sessionScope.userrole != 'Teacher'}">
                                <a href="${url}Payment?next=1"><img src="${url}images/cart.png" />(<strong>${fn:length(sessionScope.cart.cart)}</strong>) ${uq_cart}</a>
                            </c:if>
                        </span>
                    </div>
                </div>  
            </c:when>
            <c:otherwise>
                <form action="${url}LoginController" method="post">                                        
                    <input type="hidden" value="${url}<%=Url.getUrl(request)%>" name="redir"/>
                    <label for="login-email">${uq_email}</label><input type="email" name="email" id="login-email" required />
                    <label for="login-password">${uq_password}</label><input type="password" name="password" id="login-password" required />
                    <span><a href="${url}Register">${uq_sign_up}</a> | <a href="">${uq_password_forgotten}</a></span> <input type="submit" value="${uq_login}" />
                </form>
            </c:otherwise>
        </c:choose>                
    </div>
    <!-- clear //-->
    <div class="clear"></div>
    <nav>
        <ul>
            <li><a href="${url}">Home</a></li>
            <li>
                <c:choose>
                    <c:when test="${sessionScope.userrole == 'Student'}">
                        <a href="MyCourses">${uq_my_courses}</a>
                    </c:when>
                    <c:when test="${sessionScope.userrole == 'Teacher' || sessionScope.userrole == 'Administrator'}">
                        <a href="MyCourses">${uq_my_lessons}</a>
                    </c:when>
                    <c:otherwise>
                        <a href="${url}Page?p=membership">${uq_membership}</a>
                    </c:otherwise>
                </c:choose>
            </li>
            <li><a href="${url}Page?p=about">${uq_about}</a></li>
            <li><a href="${url}Page?p=contact">Contact</a></li>
            <li><a href="${url}Page?p=help">Help</a></li>
        </ul>
        <div class="search">
            <form method="get" action="${url}Search">
                <input type="text" name="k" placeholder="${uq_input_search}" value="<% if (request.getParameter("k") != null) { out.println(request.getParameter("k")); } %>" required />
                <input type="submit" value="" />
            </form>
        </div>
    </nav>
    <!-- clear //-->
    <div class="clear"></div>
    <c:if test="${sessionScope.userrole == 'Teacher' || sessionScope.userrole == 'Administrator'}">
        <div class="manage-navigation">
            <c:if test="${sessionScope.userrole == 'Administrator'}">
                <!-- admin //-->
                <div class="title">
                    ${uq_administrator}
                </div>
                <div class="option-block-25">
                    <a href="${url}Category?edit"><img src="${url}images/manage-categories.png" />${uq_manage_categories_and_courses}</a>
                </div>
                <div class="option-block-25">
                    <a href="${url}Teacher"><img src="${url}images/manage-teachers.png" />${uq_manage_teachers}</a>
                </div>
                <div class="option-block-25">
                    <a href="${url}Payment"><img src="${url}images/manage-payment.png" />${uq_manage_payments}</a>
                </div>
                <div class="option-block-25">
                    <a href="${url}ManagePage"><img src="${url}images/manage-pages.png" />${uq_manage_pages}</a>
                </div>
                <div class="clear border-bottom margin-bottom-5 padding-top-8"></div>
            </c:if>
            <!-- teacher //-->
            <div class="title">
                ${uq_teacher}
            </div>
            <div class="option-block">
                <a href="${url}Student"><img src="${url}images/manage-student-progress.png" />${uq_manage_student_progress}</a>
            </div>
            <div class="option-block">
                <a href="${url}CourseLessonEdit"><img src="${url}images/manage-lessons.png" />${uq_manage_lessons}</a>
            </div>
            <div class="option-block">
                <a href="${url}Quiz"><img src="${url}images/manage-quizzes.png" />${uq_manage_quizzes}</a>
            </div>
        </div>
    </c:if>
    <!-- clear //-->
    <div class="clear"></div>
    <div class="breadcrumbs">
        <c:set var="iteration" value="0" />
        <c:forEach items="${breadcrumbs}" var="breadcrumb">
            <c:set var="iteration" value="${iteration + 1}" />
            <c:choose>
                <c:when test="${iteration == fn:length(breadcrumbs)}">
                    <strong>${breadcrumb.name}</strong>
                </c:when>
                <c:otherwise>
                    <a href="${url}${breadcrumb.link}">${breadcrumb.name}</a> &raquo;
                </c:otherwise>
            </c:choose>
        </c:forEach>
    </div>
    <div class="languages">
        <a href="${url}Language?lang=dutch"><img src="${url}images/nl-flag.png" /></a>
        <a href="${url}Language?lang=english"><img src="${url}images/en-flag.png" /></a>
    </div>
    <!-- clear //-->

    <div class="clear"></div>
    <%HttpSession s = request.getSession();%>
    <c:if test="${login_fail eq 'true' || sesregSucses eq 'true' || activation_false eq 'true'}">
        ${jquery}        
    </c:if>
    <c:if test="${login_fail eq 'true' }">                                                                 
        <div class="loginfail"></div>            
        <% s.setAttribute("login_fail", "false");%>               
    </c:if>    
    <c:if test="${sesregSucses eq 'true'}">                
        <div class="regSucses"></div> 
        <% s.setAttribute("sesregSucses", "false");%>                  
    </c:if>     
    <c:if test="${activation_false eq 'true'}">                
        <div class="activatefalse"></div> 
        <% s.setAttribute("activation_false", "false");%>                  
    </c:if>                                                     
</header>




